package com.blog.demo.service;

import com.blog.demo.entity.User;
import com.blog.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Author : JiangLinHan
 * Date : 2019/6/14
 * Time : 11:36
 *
 * @Transactional: back
 **/
@Transactional
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    // 查询所有用户
    @Override
    public List<User> findAll() {
        return userRepository.findAll();
    }

    // 根据id查询用户信息
    @Override
    public User findAllById(long id) {
        return userRepository.findAllById(id);
    }

    // 根据id删除用户
    @Override
    public void deleteAllById(long id) {
        userRepository.deleteAllById(id);
    }

    // 存入用户 - 修改通用
    public void save(User user){
        userRepository.save(user);
    }

}
